home *** CD-ROM | disk | FTP | other *** search
/ Dr. Windows 3 / dr win3.zip / dr win3 / PROGRAMR / OLE2BOOK.ZIP / CHAP12.ZIP / PATRON / PATRON.CPP < prev    next >
C/C++ Source or Header  |  1993-06-27  |  14KB  |  570 lines

  1. /*
  2.  * PATRON.CPP
  3.  * Modifications for Chapter 12
  4.  *
  5.  * WinMain which is all we need for the basic application.
  6.  *
  7.  * Copyright (c)1993 Microsoft Corporation, All Rights Reserved
  8.  *
  9.  * Kraig Brockschmidt, Software Design Engineer
  10.  * Microsoft Systems Developer Relations
  11.  *
  12.  * Internet  :  kraigb@microsoft.com
  13.  * Compuserve:  >INTERNET:kraigb@microsoft.com
  14.  */
  15.  
  16.  
  17. #define INITGUIDS
  18. #include "patron.h"
  19.  
  20.  
  21.  
  22. /*
  23.  * WinMain
  24.  *
  25.  * Purpose:
  26.  *  Main entry point of application.   Should register the app class
  27.  *  if a previous instance has not done so and do any other one-time
  28.  *  initializations.
  29.  */
  30.  
  31. int PASCAL WinMain (HINSTANCE hInst, HINSTANCE hPrev
  32.     , LPSTR pszCmdLine, int nCmdShow)
  33.     {
  34.     LPCPatronFrame  pFR;
  35.     FRAMEINIT       fi;
  36.     WPARAM          wRet;
  37.  
  38.    #ifndef WIN32
  39.     SetMessageQueue(96);
  40.    #endif
  41.  
  42.     //Attempt to allocate and initialize the application
  43.     pFR=new CPatronFrame(hInst, hPrev, pszCmdLine, nCmdShow);
  44.  
  45.     fi.idsMin=IDS_FRAMEMIN;
  46.     fi.idsMax=IDS_FRAMEMAX;
  47.     fi.idsStatMin=IDS_STATMESSAGEMIN;
  48.     fi.idsStatMax=IDS_STATMESSAGEMAX;
  49.     fi.idStatMenuMin=ID_MENUFILE;
  50.     fi.idStatMenuMax=ID_MENUHELP;
  51.     fi.iPosWindowMenu=WINDOW_MENU;
  52.     fi.cMenus=CMENUS;
  53.  
  54.     //If we can initialize pFR, start chugging messages
  55.     if (pFR->FInit(&fi))
  56.         wRet=pFR->MessageLoop();
  57.  
  58.     delete pFR;
  59.     return wRet;
  60.     }
  61.  
  62.  
  63.  
  64.  
  65. /*
  66.  * CPatronFrame::CPatronFrame
  67.  * CPatronFrame::~CPatronFrame
  68.  *
  69.  * Constructor Parameters:
  70.  *  hInst           HINSTANCE from WinMain
  71.  *  hInstPrev       HINSTANCE from WinMain
  72.  *  pszCmdLine      LPSTR from WinMain
  73.  *  nCmdShow        int from WInMain
  74.  */
  75.  
  76. CPatronFrame::CPatronFrame(HINSTANCE hInst, HINSTANCE hInstPrev
  77.     , LPSTR pszCmdLine, int nCmdShow)
  78.     : CFrame(hInst, hInstPrev, pszCmdLine, nCmdShow)
  79.     {
  80.     m_fInitialized=FALSE;
  81.     return;
  82.     }
  83.  
  84.  
  85. CPatronFrame::~CPatronFrame(void)
  86.     {
  87.     OleFlushClipboard();
  88.  
  89.     if (m_fInitialized)
  90.         OleUninitialize();
  91.     return;
  92.     }
  93.  
  94.  
  95.  
  96.  
  97. /*
  98.  * CPatronFrame::FInit
  99.  *
  100.  * Purpose:
  101.  *  Call OleInitialize then calling down into the base class
  102.  *  initialization.
  103.  *
  104.  * Parameters:
  105.  *  pFI             LPFRAMEINIT containing initialization parameters.
  106.  *
  107.  * Return Value:
  108.  *  BOOL            TRUE if initialization succeeded, FALSE otherwise.
  109.  */
  110.  
  111. BOOL CPatronFrame::FInit(LPFRAMEINIT pFI)
  112.     {
  113.     DWORD       dwVer;
  114.  
  115.     dwVer=OleBuildVersion();
  116.  
  117.     if (rmm!=HIWORD(dwVer))
  118.         return FALSE;
  119.  
  120.     if (FAILED(OleInitialize(NULL)))
  121.         return FALSE;
  122.  
  123.     m_fInitialized=TRUE;
  124.  
  125.     return CFrame::FInit(pFI);
  126.     }
  127.  
  128.  
  129.  
  130.  
  131.  
  132. /*
  133.  * CPatronFrame::CreateCClient
  134.  *
  135.  * Purpose:
  136.  *  Constructs a new client specific to the application.
  137.  *
  138.  * Parameters:
  139.  *  None
  140.  *
  141.  * Return Value:
  142.  *  LPCClient       Pointer to the new client object.
  143.  */
  144.  
  145. LPCClient CPatronFrame::CreateCClient(void)
  146.     {
  147.     return (LPCClient)(new CPatronClient(m_hInst));
  148.     }
  149.  
  150.  
  151.  
  152.  
  153.  
  154.  
  155. /*
  156.  * CPatronFrame::FRegisterAllClasses
  157.  *
  158.  * Purpose:
  159.  *  Registers all classes used in this application.
  160.  *
  161.  * Parameters:
  162.  *  None
  163.  *
  164.  * Return Value:
  165.  *  BOOL            TRUE if registration succeeded, FALSE otherwise.
  166.  */
  167.  
  168. BOOL CPatronFrame::FRegisterAllClasses(void)
  169.     {
  170.     WNDCLASS        wc;
  171.  
  172.     //First let the standard frame do its thing
  173.     if (!CFrame::FRegisterAllClasses())
  174.         return FALSE;
  175.  
  176.     //We need double-clicks now and for object activation later.
  177.     wc.style         = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS;
  178.     wc.hInstance     = m_hInst;
  179.     wc.cbClsExtra    = 0;
  180.     wc.lpfnWndProc   = PagesWndProc;
  181.     wc.cbWndExtra    = CBPAGESWNDEXTRA;
  182.     wc.hIcon         = NULL;
  183.     wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
  184.     wc.hbrBackground = (HBRUSH)(COLOR_APPWORKSPACE+1);
  185.     wc.lpszMenuName  = NULL;
  186.     wc.lpszClassName = SZCLASSPAGES;
  187.  
  188.     if (!RegisterClass(&wc))
  189.         return FALSE;
  190.  
  191.     return TRUE;
  192.     }
  193.  
  194.  
  195.  
  196.  
  197.  
  198. /*
  199.  * CPatronFrame::OnCommand
  200.  *
  201.  * Purpose:
  202.  *  WM_COMMAND handler for the Patron frame window that processes extra
  203.  *  File menu items as well as the Page menu.
  204.  *
  205.  * Parameters:
  206.  *  hWnd            HWND of the frame window.
  207.  *  wParam          WPARAM of the message.
  208.  *  lParam          LPARAM of the message.
  209.  *
  210.  * Return Value:
  211.  *  LRESULT         Return value for the message.
  212.  */
  213.  
  214. LRESULT CPatronFrame::OnCommand(HWND hWnd, WPARAM wParam, LPARAM lParam)
  215.     {
  216.     LPCPatronDoc    pDoc;
  217.  
  218.     COMMANDPARAMS(wID, wCode, hWndMsg);
  219.  
  220.     /*
  221.      * Don't bother with anything during first initialization,
  222.      * skipping many GizmoBar notifications.
  223.      */
  224.     if (m_fInit)
  225.         return 0L;
  226.  
  227.     pDoc=(LPCPatronDoc)m_pCL->ActiveDocument();
  228.  
  229.     if (NULL!=pDoc && (IDM_VERBMIN <= wID) && (IDM_VERBMAX >= wID))
  230.         {
  231.         pDoc->ActivateObject(wID-IDM_VERBMIN);
  232.         return 0L;
  233.         }
  234.  
  235.     switch (wID)
  236.         {
  237.         case IDM_FILEPRINT:
  238.             pDoc->Print(m_hWnd);
  239.             return 0L;
  240.  
  241.         case IDM_FILEPRINTERSETUP:
  242.             pDoc->PrinterSetup(m_hWnd, FALSE);
  243.             return 0L;
  244.  
  245.  
  246.         case IDM_EDITPASTESPECIAL:
  247.             pDoc->FPasteSpecial(m_hWnd);
  248.             return 0L;
  249.  
  250.         case IDM_EDITDELETEOBJECT:
  251.             pDoc->Delete();
  252.             return 0L;
  253.  
  254.         case IDM_EDITINSERTOBJECT:
  255.             pDoc->FInsertObject(m_hWnd);
  256.             return 0L;
  257.  
  258.         //CHAPTER12MOD
  259.         case IDM_EDITLINKS:
  260.             pDoc->FEditLinks(m_hWnd);
  261.             return 0L;
  262.         //End CHAPTER12MOD
  263.  
  264.         case IDM_PAGENEWPAGE:
  265.             pDoc->NewPage();
  266.             break;
  267.  
  268.         case IDM_PAGEDELETEPAGE:
  269.             pDoc->DeletePage();
  270.             break;
  271.  
  272.         case IDM_PAGENEXTPAGE:
  273.             pDoc->NextPage();
  274.             break;
  275.  
  276.         case IDM_PAGEPREVIOUSPAGE:
  277.             pDoc->PreviousPage();
  278.             break;
  279.  
  280.         case IDM_PAGEFIRSTPAGE:
  281.             pDoc->FirstPage();
  282.             break;
  283.  
  284.         case IDM_PAGELASTPAGE:
  285.             pDoc->LastPage();
  286.             break;
  287.  
  288.         //CHAPTER12MOD
  289.         case IDM_PAGESHOWOBJECTS:
  290.             {
  291.             BOOL    fTemp;
  292.  
  293.             //First get the current state, then toggle it.
  294.             fTemp=pDoc->FShowOrQueryObjectTypes(TRUE, FALSE);
  295.             pDoc->FShowOrQueryObjectTypes(FALSE, !fTemp);
  296.             }
  297.             break;
  298.         //End CHAPTER12MOD
  299.  
  300.         default:
  301.            return CFrame::OnCommand(hWnd, wParam, lParam);
  302.         }
  303.  
  304.     return 0L;
  305.     }
  306.  
  307.  
  308.  
  309.  
  310.  
  311.  
  312.  
  313.  
  314. /*
  315.  * CPatronFrame::CreateGizmos
  316.  *
  317.  * Purpose:
  318.  *  Procedure to create all the necessary gizmobar buttons.
  319.  *
  320.  * Parameters:
  321.  *  None
  322.  *
  323.  * Return Value:
  324.  *  UINT            Number of gizmos added to the bar.
  325.  */
  326.  
  327. UINT CPatronFrame::CreateGizmos(void)
  328.     {
  329.     UINT            iLast;
  330.     UINT            uState=GIZMO_NORMAL;
  331.     UINT            utCmd =GIZMOTYPE_BUTTONCOMMAND;
  332.  
  333.     //Insert the standard ones.
  334.     iLast=CFrame::CreateGizmos();
  335.  
  336.     //Insert Print File Import in the 5th position and account for it in iLast.
  337.     m_pGB->Add(utCmd, 4, IDM_FILEPRINT, m_dxB, m_dyB, NULL, NULL, 6, uState);
  338.     iLast++;
  339.  
  340.     //Add New Page, and Delete Page
  341.     m_pGB->Add(utCmd, iLast++, IDM_PAGENEWPAGE,    m_dxB, m_dyB, NULL, m_hBmp, 2, uState);
  342.     m_pGB->Add(utCmd, iLast++, IDM_PAGEDELETEPAGE, m_dxB, m_dyB, NULL, m_hBmp, 3, uState);
  343.  
  344.     //Separator
  345.     m_pGB->Add(GIZMOTYPE_SEPARATOR, iLast++, 0, 6, m_dyB, NULL, NULL, 0, uState);
  346.  
  347.     //First, Prev, Next, Last pages.
  348.     m_pGB->Add(utCmd, iLast++, IDM_PAGEFIRSTPAGE,    m_dxB, m_dyB, NULL, m_hBmp, 4, uState);
  349.     m_pGB->Add(utCmd, iLast++, IDM_PAGEPREVIOUSPAGE, m_dxB, m_dyB, NULL, m_hBmp, 5, uState);
  350.     m_pGB->Add(utCmd, iLast++, IDM_PAGENEXTPAGE,     m_dxB, m_dyB, NULL, m_hBmp, 6, uState);
  351.     m_pGB->Add(utCmd, iLast++, IDM_PAGELASTPAGE,     m_dxB, m_dyB, NULL, m_hBmp, 7, uState);
  352.  
  353.     return iLast;
  354.     }
  355.  
  356.  
  357.  
  358.  
  359.  
  360.  
  361.  
  362. /*
  363.  * CPatronFrame::UpdateMenus
  364.  *
  365.  * Purpose:
  366.  *  Handles the WM_INITMENU message for the frame window.  Dependi